<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>用户注册</title>
		<script src="js/jquery-1.9.1.min.js"></script>
		<link rel="stylesheet" href="css/base.css" />
		<link rel="stylesheet" href="css/login.css" />
		<link rel="stylesheet" href="css/Register.css" />
		<script type="text/javascript" src="js/myDialog/dialog.js"></script>
		<script type="text/javascript" src="js/myDialog/extend/dialog.ext.js"></script>
		<script type="text/javascript" src="js/myValide/myValide.js"></script>
		<script type="text/javascript">
			$(function()
			{
				$('.registForm').Validform(
					{
						tiptype:3, 
						ignoreHidden:true,
						dragonfly:false,
						tipSweep:false,
						label:".label",
						showAllError:false,
						postonce:true,
						ajaxPost:true
					}
				);
			});
		</script>
		
		<script>
			$(function()
			{	
				var getCodeUrl="";
				var timeout=60;//十分钟
				var timer;
				var btn_regist=$("#btn_regist");
				var phone_number=$("#phone_number");
				var password=$("#password");
				var repassword=$("#repassword");
				var VerifyCode=$("#VerifyCode");
				var btn_getCode=$("#getCode");
				btn_getCode.bind("click",getCodeBtn);
				btn_regist.bind("click",regist);
				
				
				function redirect(url,phone_number)
				{ //跳转页				
					//history.back();
//					var url="foreground/fore/index";
					window.location.href=url+"?phone_number="+phone_number;//指定要跳转到的目标页面
				}
				
				function getCodeBtn()
				{
					getCode();
					btn_getCode.attr("disabled",true);
					timer=setInterval(validetime,1000);
					
				}
				
				function validetime()
				{
					btn_getCode.attr("value",'剩余'+timeout+'s');
					timeout--;
					if(timeout==0)
					{
						clearInterval(timer);
						btn_getCode.attr("disabled",false);
						btn_getCode.attr("value",'获取验证码');
						timeout=60;
					}
				}
				
				function getCode()
				{
					event.preventDefault();
					var phone_number_val=phone_number.val();
					
					console.log(phone_number_val);
					$.ajax({
						type:"get",
						url:"<%=basePath%>appMobile/sms/sendVerifyCode/"+phone_number_val+"/1",
						async:true,
						timeout:10000,
						dataType:'json',
						success:function(data,textStatus,jqXHR)
						{
							alert("验证码发送成功");
							console.log(data.code);
					        console.log(data);
					        console.log(textStatus);
					        console.log(jqXHR);
					        
					    },
					    error:function(xhr,textStatus)
					    {
					    	console.log(data.code);
					        console.log('错误');
					        console.log(xhr);
					        console.log(textStatus);
					    },
					    complete:function()
					    {
					        console.log('结束');
					    }
					});
					
				}
				
				
				function regist()
				{
					event.preventDefault();
					var phone_number_val=phone_number.val();
					var password_val=password.val();
					var repassword_val=repassword.val();
					var VerifyCode_val=VerifyCode.val();
					console.log(VerifyCode_val);
					if(password_val!=repassword_val)
					{
						alert("两次输入密码不一致！");
						//return;
					}
					
					$.ajax({
						type:"post",
						url:"pubuser/pubregister.do",
						async:true,
						data:
						{
							PHONE_NUMBER:phone_number_val,
							PASSWORD:password_val,
							VerifyCode:VerifyCode_val
						},
						timeout:10000,
						dataType:'json',
						success:function(data,textStatus,jqXHR)
						{
					        console.log(data);
					        console.log(textStatus);
					        console.log(jqXHR);
					        if(data.result=="02")
					        {
					        	layer.alert(data.message, 
							        	{
								            icon: 1,
								            skin: 'layer-ext-moon'
								        });
							        	//alert(data.message);
								        setTimeout(redirect("pubuser/foreindex.do"),1000);
					        	
					        }
					        else
					        {
					        	layer.alert(data.message, 
							        	{
								            icon: 1,
								            skin: 'layer-ext-moon'
								        });
							        	//alert(data.message);
					        }
					    },
					    error:function(xhr,textStatus)
					    {
					    	layer.alert(data.message, 
						        	{
							            icon: 1,
							            skin: 'layer-ext-moon'
							        });
					        console.log('错误');
					        console.log(xhr);
					        console.log(textStatus);
					    },
					    complete:function()
					    {
					        console.log('结束');
					    }
					});
				}
			});
		</script>
		
		
	</head>
	<body>
		<div id="login">
			<div id="login_head">
				<center>
				<div class="top">
				<img src="img/logo.png" class="logo" ></img>
				<ul class="nav">
					<li><a class="me" href="index.html">首页</a></li>
					<li><a class="me" href="index.html">资源库</a></li>
					<li><a class="me" href="index.html">公共资源库</a></li>
				</ul>
				</div>
				</center>
			</div>
			<div id="login_main">
				<form class="registForm">
					<div class="login_form">
						<center>
						<table border="0" cellpadding="0" cellspacing="0" width="320px" height="280">
							<caption class="login_title">用户注册</caption>	
							
							<tr align="center" height="80px">
								<td>
									
									<input type="text" id="PHONE_NUMBER" name="PHONE_NUMBER" datatype="n11-11" errormsg="请输入11位有效手机号" placeholder="手机号" maxlength="11" tabindex="1" style="background-image: url(img/icon_login_telephone.png);"/>
									
								</td>
							</tr>
							<tr align="center" height="80px">
								<td>
									
									<input type="password" id="PASSWORD" name="PASSWORD" datatype="*" errormsg="请输入密码" placeholder="请输入密码" tabindex="1" style="background-image: url(img/icon_login_password.png);"/>
									
								</td>
							</tr>
							<tr align="center" height="80px">
								<td>
									
									<input type="password" id="REPASSWORD" name="REPASSWORD" recheck="PASSWORD" errormsg="密码不一致" placeholder="请确认密码" tabindex="1" style="background-image: url(img/repassword.png);"/>
									
								</td>
							</tr>
							<tr align="center" height="80px">
								<td style="position: relative;">
									<input type="text" id="VALIDECODE" name="VALIDECODE" tabindex="2" placeholder="验证码" style="background-image: url(img/validatecode.png);"/>
									<input id="getCode" class="ico_code" value="获取验证码"></input>
							</tr>
							<tr align="center"  height="80px"><td><input id="btn_login" type="button" value="注			册"/></td></tr>
						</table>
						<span><a class="me" href="login.html">已有有账号？&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;立即登录</a></span>
						</center>
					
					</div>
				</form>
				
			</div>
			<div id="login_foot">
				<center>
					<article>
						<p><a class="me" href="#">技术支持</a>&nbsp;|&nbsp;<a class="me" href="#">关于我们</a></p>
						<br />
						<p><a href="#" class="me">宁夏欣光泰电力有限公司（0951-8361518）</a> </p>
					</article>
				</center>
			</div>
		</div>
	</body>
</html>
